#include "checknetworkconnect.h"

CheckNetWorkConnect::CheckNetWorkConnect()
{
    running = true;
}

void CheckNetWorkConnect::stop()
{
    running = false;
}

void CheckNetWorkConnect::run()
{
    QString cmd = "ping www.baidu.com -c 1 -W 1";
    QString result;
    process = new QProcess();
    while(running)
    {
        process->start(cmd);
        process->waitForFinished(1500);
        result = process->readAll();
        if(result.contains(QString("TTL="))||result.contains(QString("ttl=")))
        {
            emit send_networkConnect_state(1);
        }
        else
        {
            emit send_networkConnect_state(0);
        }
    }
}
